package com.maya.medicalwastes.httpNet.converter;

import java.io.IOException;
import java.nio.charset.Charset;

import retrofit2.Converter;

/**
 * 对含中文的字符串进行utf8编码
 * Created by 吕自聪 on 2018/3/28.
 */

public class Utf8StringConverter<T> implements Converter<T, String> {
    private static final Charset UTF_8 = Charset.forName("UTF-8");

    @Override
    public String convert(T value) throws IOException {
        String v = String.valueOf(value);
//        如果含中文则进行utf8编码
        if ((v.length() != v.getBytes().length))
            return new String(String.valueOf(value).getBytes(), "UTF-8");
        return v;
    }
}
